﻿using Shop.RemoteModel.Coupon;
using Shop.RemoteModel.Coupon.Model;
using Shop.StoreGatewayModular.Interface;
using Shop.StoreGatewayModular.Model.Coupon;
using WeDonekRpc.Client;
using WeDonekRpc.HttpApiGateway.Model;

namespace Shop.StoreGatewayModular.Service
{
    internal class CouponService : ICouponService
    {
        public long Add (CouponSet data)
        {
            return new AddCoupon
            {
                Datum = data
            }.Send();
        }

        public void Delete (long id)
        {
            new DeleteCoupon
            {
                Id = id
            }.Send();
        }

        public bool Enable (long id)
        {
            return new EnableCoupon
            {
                Id = id
            }.Send();
        }

        public CouponDetailed Get (long id)
        {
            CouponDto dto = new GetCoupon
            {
                Id = id
            }.Send();
            CouponDetailed detailed = dto.ConvertMap<CouponDto, CouponDetailed>();
            detailed.ReceiveTypeName = detailed.ReceiveType.ToString();
            return detailed;
        }

        public bool Offshelf (long id)
        {
            return new OffshelfCoupon
            {
                Id = id
            }.Send();
        }

        public PagingResult<CouponDatum> Query (PagingParam<CouponQueryParam> param)
        {
            return new QueryCoupon
            {
                Query = param.Query,
                Size = param.Size,
                SortName = param.SortName,
                Index = param.Index,
                IsDesc = param.IsDesc,
                NextId = param.NextId,
            }.Send();
        }

        public bool Set (long id, CouponSet data)
        {
            return new SetCoupon
            {
                Id = id,
                Datum = data
            }.Send();
        }

        public bool Stop (long id)
        {
            return new StopCoupon
            {
                Id = id
            }.Send();
        }
    }
}
